﻿<UserControl x:Class="MaxStoreShop.CoreModule.Login.LoginView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:converters="clr-namespace:MaxStoreErp.Core.Converters;assembly=MaxStoreErp.Core"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:login="clr-namespace:MaxStoreShop.CoreModule.Login"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:security="clr-namespace:MaxStoreErp.Core.Security;assembly=MaxStoreErp.Core"
             d:DataContext="{d:DesignInstance login:LoginViewModel}"
             d:DesignHeight="400"
             d:DesignWidth="400"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
                <ResourceDictionary Source="../Resources/Images.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Style x:Key="Heading1" TargetType="TextBlock">
                <Setter Property="FontFamily" Value="Segoe UI" />
                <Setter Property="FontSize" Value="30" />
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
            </Style>
            <Style x:Key="Heading2" TargetType="TextBlock">
                <Setter Property="FontFamily" Value="Segoe UI" />
                <Setter Property="FontSize" Value="16" />
                <Setter Property="FontWeight" Value="Bold" />
                <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
            </Style>

            <Style x:Key="LoginTextStyle"
                   BasedOn="{StaticResource Heading1}"
                   TargetType="{x:Type TextBlock}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsBusy}" Value="True">
                        <DataTrigger.Setters>
                            <Setter Property="Text" Value="Загрузка пользователей, подождите немного..." />
                        </DataTrigger.Setters>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsBusy}" Value="False">
                        <DataTrigger.Setters>
                            <Setter Property="Text" Value="Пожалуйста, представьтесь!" />
                        </DataTrigger.Setters>
                    </DataTrigger>

                </Style.Triggers>
            </Style>
            <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
            <converters:NullImageConverter x:Key="NullImageConverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>

        <StackPanel HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Orientation="Vertical">
            <TextBlock HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       Style="{DynamicResource LoginTextStyle}" />
            <controls:MetroProgressBar Margin="0,20,0,0"
                                       IsIndeterminate="True"
                                       Visibility="{Binding IsBusy,
                                                            Converter={StaticResource BooleanToVisibilityConverter}}" />
            <Image Width="100"
                   Height="133"
                   Source="{Binding SelectedUser.FotoRaw,
                                    Converter={StaticResource NullImageConverter}}" />
        </StackPanel>

        <Grid Grid.Row="1"
              HorizontalAlignment="Center"
              VerticalAlignment="Top"
              FocusManager.FocusedElement="{Binding ElementName=UserComboBox}"
              Visibility="{Binding IsBusy,
                                   Converter={StaticResource BooleanToVisibilityConverter},
                                   ConverterParameter=inverse}">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBlock Margin="6"
                       Style="{StaticResource Heading2}"
                       Text="Меня зовут:" />
            <TextBlock Grid.Row="1"
                       Grid.Column="0"
                       Margin="6"
                       Style="{StaticResource Heading2}"
                       Text="Мой пароль:" />
            <ComboBox Name="UserComboBox"
                      Grid.Row="0"
                      Grid.Column="1"
                      MinWidth="200"
                      Margin="6"
                      DisplayMemberPath="DisplayName"
                      ItemsSource="{Binding Users}"
                      SelectedItem="{Binding SelectedUser,
                                             Mode=TwoWay}" />

            <PasswordBox Name="PasswordBox"
                         Grid.Row="1"
                         Grid.Column="1"
                         Margin="6"
                         security:PasswordBoxAssistant.BindPassword="true"
                         security:PasswordBoxAssistant.BoundPassword="{Binding Path=Password,
                                                                               Mode=TwoWay,
                                                                               UpdateSourceTrigger=PropertyChanged}" />
            <Button Grid.Row="0"
                    Grid.RowSpan="2"
                    Grid.Column="2"
                    Width="44"
                    Height="44"
                    BorderThickness="0"
                    Command="{Binding EnterCommand}"
                    IsDefault="True"
                    Style="{DynamicResource MetroCircleButtonStyle}"
                    ToolTip="Войти">
                <Path Width="32"
                      Height="32"
                      Data="{StaticResource EnterIcon}"
                      Fill="{DynamicResource BlackBrush}"
                      Stretch="Uniform" />
            </Button>
            <TextBlock Grid.Row="2"
                       Grid.Column="0"
                       Grid.ColumnSpan="3"
                       HorizontalAlignment="Center"
                       FontSize="14"
                       Foreground="Red"
                       Text="{Binding ErrorText}"
                       Visibility="{Binding IsErrorOccured,
                                            Converter={StaticResource BooleanToVisibilityConverter}}" />
        </Grid>
    </Grid>
</UserControl>
